package com.dmbjz.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;


@Document(value = "springboot")                         //指定使用的集合名称，如果不填将调用类名小写集合
@CompoundIndex(def = "{'userid'=1,'likenum'=1}")        //使用聚合索引查询这两个字段
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class Comment implements Serializable {


    @Id
    private String id;                              //主键,注解意为对应 _id，如果数据的主键字段不为 _id需要添加@Id注解

    @Field("content")
    private String contents;                        //评论内容,注解对应mongodb的字段的名字，如果一致，则无需该注解

    @Indexed
    private String userid;                          //发布人ID,注解意为建立单字段索引，一般通过命令行而不是代码建立索引

    private Date publishtime;                       //发布日期
    private String nickname;                        //昵称
    private LocalDateTime createdatetime;           //评论的日期时间
    private Integer likenum;                        //点赞数
    private Integer replynum;                       //回复数
    private String state;                           //状态

    public Comment(String contents, String userid, Date publishtime, String nickname, LocalDateTime createdatetime, Integer likenum, Integer replynum, String state) {
        this.contents = contents;
        this.userid = userid;
        this.publishtime = publishtime;
        this.nickname = nickname;
        this.createdatetime = createdatetime;
        this.likenum = likenum;
        this.replynum = replynum;
        this.state = state;
    }


}
